/* @(#)GSFileUploadProcessor.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-20
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package system.imp;

import java.io.DataInputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import system.base.ClientDownupfileInfo;
import system.base.Product;
import system.base.ProductCategory;
import system.base.Provider;
import system.base.Warehouse;
import system.base.WarehouseCategory;
import framework.core.ConstDefine;
import framework.core.DBConnection;
import framework.core.DateUtil;
import framework.core.ILoginContext;
import framework.core.LogWriter;


/**
 * 导入Excel文件到数据库
 */
public class GWFileUploadProcessor implements GWBaseProcesser{
    /**
     * 批量导入产品信息
     * @param aFile
     * @throws CUPSException
     */
    public static String batchImportManufacture(DataInputStream aFile, DBConnection con, ILoginContext loginContext) throws GWException 
    {
        int tSuccCount = 0;
        int tFailCount = 0;
        String tFailFile = "0";
        HSSFWorkbook tHSSFWorkbook = new HSSFWorkbook();
        HSSFSheet tHSSFSheet = null;
        try{
            //开始读取excel文件
            tHSSFWorkbook = new HSSFWorkbook(aFile);           //读取sheet表单
            //读取sheet表单
            tHSSFSheet = tHSSFWorkbook.getSheetAt(0);
        }catch(Exception e){
            //e.printStackTrace();
            LogWriter.error(e.getMessage());
            throw new GWException("批量上传文件失败");
        }
            ArrayList tList = new ArrayList();
            ArrayList tErrList = new ArrayList();
            ArrayList tSuccList = new ArrayList();
            //读取并检查明细
            int tRowCount =getManufactureContents(tList,tHSSFSheet, loginContext);
            
            if(tList.size() > 0){
                for(int i=0; i<tList.size(); i++){
                    GWManufactureUploadVO tGSManufactureUploadVO = (GWManufactureUploadVO)tList.get(i);
                    Product p = tGSManufactureUploadVO.getProduct();

                    int tResult = Integer.parseInt(tGSManufactureUploadVO.getInsert_result());
                    if(tResult == 1){
                        tGSManufactureUploadVO.setProduct(p);
                       try{
                           
                           //判断是否存在产品信息
                           Product obj = Product.fetchByConcentricityCode(con, p.getConcentricityCode());
                           if(obj == null) obj = Product.fetchByApepCode(con, p.getApepCode());
                           if(obj == null) 
                               obj = Product.fetch();
                           obj.setAdaptMachineType(p.getAdaptMachineType());
                           obj.setApepCode(p.getApepCode());
                           obj.setAppenderProperty(p.getAppenderProperty());
                           obj.setArea(p.getArea());
                           obj.setBalanceMode(p.getBalanceMode());
                           obj.setCategoryCode(p.getCategoryCode());
                           obj.setConcentricityCode(p.getConcentricityCode());
                           obj.setCreateTime(p.getCreateTime());
                           obj.setCreateUser(p.getCreateUser());
                           obj.setCreateUserId(p.getCreateUserId());
                           obj.setDrawingPieceCode(p.getDrawingPieceCode());
                           obj.setIsBuy(p.getIsBuy());
                           obj.setIsNormal(p.getIsNormal());
                           obj.setIsTradeflatProduct(p.getIsTradeflatProduct());
                           obj.setLastUpdateTime(p.getLastUpdateTime());
                           obj.setLastUpdateUser(p.getLastUpdateUser());
                           obj.setLastUpdateUserId(p.getLastUpdateUserId());
                           obj.setManufaturer(p.getManufaturer());
                           obj.setModel(p.getModel());
                           obj.setName(p.getName());
                           obj.setPic(p.getPic());
                           obj.setProductBrand(p.getProductBrand());
                           obj.setProductUnit(p.getProductUnit());
                           obj.setProviderCode(p.getProviderCode());
                           obj.setQualityAssurePeriod(p.getQualityAssurePeriod());
                           obj.setRecentAdjustedPrice(p.getRecentAdjustedPrice());
                           obj.setRecentAdjustpriceDate(p.getRecentAdjustpriceDate());
                           obj.setRecordDate(p.getRecordDate());
                           obj.setRecorderId(p.getRecorderId());
                           obj.setRemark(p.getRemark());
                           obj.setSpec(p.getSpec());
                           obj.setStatus(p.getStatus());
                           obj.setUnitPrice(p.getUnitPrice());
                           
                           //所有正式产品的所属仓库默认为总库
                           obj.setWarehouseCode(Warehouse.WAREHOUSE_CODE_HEAD);
                           obj.setWarehouseName(Warehouse.WAREHOUSE_CODE_HEAD_NAME);
                           
                           //old
                           //obj.setWarehouseCode(p.getWarehouseCode());
                           //obj.setWarehouseName(p.getWarehouseName());
                           
                           obj.save(con);
                           
                           tSuccCount ++;
                           tGSManufactureUploadVO.setInsert_result("1");
                           tSuccList.add(tGSManufactureUploadVO);
                       }catch(Exception e){
                           tFailCount++;
                           tGSManufactureUploadVO.setInsert_result("0");
                           tGSManufactureUploadVO.setFailure_reason(e.getMessage());
                           tErrList.add(tGSManufactureUploadVO);
                       }
                    }else if(tResult == 0){
                        tFailCount++;
                        tErrList.add(tGSManufactureUploadVO);
                    }
                    
                }
            }
            //为更新的产品表同步产品过滤表
            //int value = tGSManufactureDAO.filter();
            //将新增失败的商户信息写入文件
            if(tErrList.size() > 0){
                tFailFile = writeManufactureFile(tErrList,tSuccList,tHSSFWorkbook,tRowCount);
            }
            return tSuccCount+"-"+tFailCount+"-"+tFailFile;
        }
    //start chengbiao.he
    /*加入分类信息*/
    public static String doCatory(DataInputStream aFile, DBConnection con, ILoginContext loginContext) throws GWException 
    
    
    {   int tSuccCount = 0;
        int tFailCount = 0;
        String tFailFile = "0";
        HSSFWorkbook tHSSFWorkbook = new HSSFWorkbook();
        //开始读取excel文件
        HSSFSheet tHSSFSheet = null;
        try{
        tHSSFWorkbook = new HSSFWorkbook(aFile); 
        tHSSFSheet=tHSSFWorkbook.getSheetAt(0);
        }catch(IOException e){
            e.getStackTrace();
                    new Exception("批量上传文件失败");
        }
        ArrayList alist = new ArrayList();
        ArrayList tsucceslist = new ArrayList();
        ArrayList tErrList = new ArrayList();
        
        //读取并检查Excel明细
        int tRowCount = getManuCatory( alist, tHSSFSheet, loginContext);
        if(alist.size()>0){
            //保存上传文件到数据库
            for(int i = 0 ;i<alist.size();i++){
                try{
                    GWManufactureUploadVO gwManufactureUpload =(GWManufactureUploadVO)alist.get(i);
                    WarehouseCategory wc = gwManufactureUpload.getWarehouseCategory();
                    
                    //判断数据库中是否存在该条记录
                    WarehouseCategory warehouseCategory = WarehouseCategory.fetch(con,wc.getId());
                    if (warehouseCategory == null)
                    {
                        //数据库中不存在的操作
                        warehouseCategory = WarehouseCategory.fetch();
                    }
                    
                    //更新数据库该条数据信息
                    warehouseCategory.setWarehouseCode(wc.getWarehouseCode());
                    warehouseCategory.setWarehouseName(wc.getWarehouseName());
                    
                    
                    warehouseCategory.save(con);                     
                }
                catch(Exception e)
                {
                    
                }
            }
            //在循环结束后在客户上传下载表中记录操作信息
            try{
                ClientDownupfileInfo clientDownupfileInfo = new ClientDownupfileInfo();
                ClientDownupfileInfo cdfi = ClientDownupfileInfo.fetch();
                cdfi.setCreateTime(new DateUtil().getDateString());
                cdfi.setCreateUser(loginContext.getLoginUserName() );
                cdfi.setCreateUserId(loginContext.getLoginUserId());
                cdfi.setDownloadtyp("上传");
                cdfi.setLastUpdateTime(new DateUtil().getDateString());
                cdfi.setLastUpdateUser(loginContext.getLoginUserName());
                cdfi.setLastUpdateUserId(loginContext.getLoginUserId());
                cdfi.setParmsstr("");
                cdfi.setParmstype("");
                cdfi.setStatus("1");
                cdfi.setUpdownState("0");
                cdfi.setWarehouseUincode(loginContext.getLoginWarehouseCode());
                cdfi.save(con);
            }
            catch(Exception e)
            {
                
            }
            
        }
        //读取sheet表单
       return tSuccCount+"-"+tFailCount+"-"+tFailFile+tRowCount;
    }
    //end chengbiao.he


	
	/**
	 * 批量导入过滤产品信息
	 * @param aFile
	 * @throws CUPSException
	 */
	/*public static String batchImportFilterManufacture(DataInputStream aFile,String aUserName) throws GSException 
	{
		int tSuccCount = 0;
		int tFailCount = 0;
		String tFailFile = "0";
		HSSFWorkbook tHSSFWorkbook = new HSSFWorkbook();
		HSSFSheet tHSSFSheet = null;
		try{
			//开始读取excel文件
			tHSSFWorkbook = new HSSFWorkbook(aFile);           //读取sheet表单
			//读取sheet表单
			tHSSFSheet = tHSSFWorkbook.getSheetAt(0);
		}catch(Exception e){
			//e.printStackTrace();
			LogWriter.error(e.getMessage());
			throw new GSException("批量导入过滤产品失败");
		}
			
		ArrayList tList = new ArrayList();
		ArrayList tErrList = new ArrayList();
		ArrayList tSuccList = new ArrayList();
		//读取并检查明细
		int tRowCount =getManufactureFilterContents(tList,tHSSFSheet);
		GSManufactureFilterUploadDAO tGSManufactureFilterUploadDAO=new GSManufactureFilterUploadDAO();
            
		if(tList.size() > 0)
		{
			for(int i=0; i<tList.size(); i++)
			{
				GSManufactureFilterUploadVO tGSManufactureFilterUploadVO = (GSManufactureFilterUploadVO)tList.get(i);
				GSManufactureFilterUploadBean tGSManufactureFilterUploadBean = tGSManufactureFilterUploadVO.getGSManufactureFilterUploadBean();

				int tResult = Integer.parseInt(tGSManufactureFilterUploadVO.getInsert_result());
				if(tResult == 1)
				{
					tGSManufactureFilterUploadVO.setGSManufactureFilterUploadBean(tGSManufactureFilterUploadBean);
					try
					{
						//判断是否存在产品信息
						if(new GSManufactureFilterUploadDAO().isExist(tGSManufactureFilterUploadBean.getGs_manufacture_id()))
						{
							//更新产品信息
							tGSManufactureFilterUploadDAO.modify(tGSManufactureFilterUploadBean);   
						}
						else
						{
							//新增产品信息
							tGSManufactureFilterUploadDAO.add(tGSManufactureFilterUploadBean);
						}
						tSuccCount ++;
						//System.out.println(tSuccCount+"记录");
						tGSManufactureFilterUploadVO.setInsert_result("1");
						tSuccList.add(tGSManufactureFilterUploadVO);
					}
					catch(Exception e)
					{
						tFailCount++;
						tGSManufactureFilterUploadVO.setInsert_result("0");
						tGSManufactureFilterUploadVO.setFailure_reason(e.getMessage());
						tErrList.add(tGSManufactureFilterUploadVO);
					}
				}
				else if(tResult == 0)
				{
					tFailCount++;
					tErrList.add(tGSManufactureFilterUploadVO);
				}
                    
			}
		}
		
		//将导入失败的筛选产品信息写入文件
		if(tErrList.size() > 0){
			tFailFile = writeManufactureFilterUploadFile(tErrList,tSuccList,tHSSFWorkbook,tRowCount);
		}
		
		return tSuccCount+"-"+tFailCount+"-"+tFailFile;
	}*/
    
    /**
     * 读取excel产品信息文档内容
     * @param aList             ArrayList对象，存放读到的内容
     * @param aSheet            表单
     * @throws CUPSException
     */
    private static int getManufactureContents(ArrayList aList,HSSFSheet aHSSFSheet, ILoginContext loginContext) throws GWException{
        int i = 0;
        //取得第一行的对象
        HSSFRow tFirstRow = aHSSFSheet.getRow(0);
        DecimalFormat a = new DecimalFormat("#");
        while(true){
           HSSFRow tHSSFRow = aHSSFSheet.getRow(1 + i);
            boolean flag = false;
            try{
                
                for(int j=0; j<21; j++){
                   if(tHSSFRow == null){
                        break;
                    }
                    if(tHSSFRow.getCell((short)j) == null){
                        break;
                    }
                   flag=true;
                   break;
                }
                if(!flag){
                    break;
                }else{
                    GWManufactureUploadVO tGSManufactureUploadVO=new GWManufactureUploadVO();
                    int tResult = 1;
                    String tFailReason = "";
                    Product product = new Product();

                    for(int j=0; j<21; j++){
                       //获得EXCEL首行记录
                       String tFiledName = tFirstRow.getCell((short)j).getStringCellValue();
                        //产品编号
                        if(tFiledName.equals("ManufactureId")){
                            String tProductID= PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setApepCode(tProductID);
 
                         //集中编码   
                        }else if(tFiledName.equals("ConcentricityCode")){
                            String tConcentricityCode = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setConcentricityCode(tConcentricityCode);
                            
                         //产品名称
                        }else if(tFiledName.equals("ManufactureName")){
                            String tProductName = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setName(tProductName);
                            
                          //产品种类编号  
                        }else if(tFiledName.equals("ManufactureCategoryId")){
                            String tCategoryCode = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setCategoryCode(tCategoryCode);
                            
                        //产品品牌  
                        }else if(tFiledName.equals("ManufactureBrand")){
                            String tProductBrand = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setProductBrand(tProductBrand);
                        
                         //产品型号   
                        }else if(tFiledName.equals("ManufactureType")){
                            String tProductType = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setModel(tProductType);
                        
                         //产品规格  
                        }else if(tFiledName.equals("ManufactureSpec")){
                            String tProductSpec = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setSpec(tProductSpec);
                            
                        //产品单价
                        }else if(tFiledName.equals("ManufactureUnitprice")){
                            String tProductPrice = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            product.setUnitPrice(Double.parseDouble(tProductPrice));
                        //数量单位  
                        }else if(tFiledName.equals("QuantUnit")){
                            String tProductUnit = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setProductUnit(tProductUnit);
                        //质保期   
                        }else if(tFiledName.equals("QualityAssurePeriod")){
                            String tAssurePeriod = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setQualityAssurePeriod(tAssurePeriod);
                            
                        //生产厂商名称    
                        }else if(tFiledName.equals("ManufacturerName")){
                            String tManufacturer = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setManufaturer(tManufacturer);
                            
                        //产地   
                        }else if(tFiledName.equals("MakeArea")){
                            String tMakeArea = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setArea(tMakeArea);
                            
                         //供应商编号
                        }else if(tFiledName.equals("ProviderId")){
                            String tCompanyID = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setProviderCode(tCompanyID);
                             
                        //适用机型  
//                        }else if(tFiledName.equals("MachineType")){
//                           if(!(tHSSFRow.getCell((short)j)==null)){
//                           String tMachineType = tHSSFRow.getCell((short)j).getStringCellValue().trim();
//                           tGSManufactureBean.setGs_adapt_machine_type(tMachineType);
//                           }
                        //产品图片  
                        }else if(tFiledName.equals("ManufactureImage")){
                            String tProductImage = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setPic(tProductImage);
                        //最近调价价格时间  
                        }else if(tFiledName.equals("RecentAdjustpriceDate")){
                            String tRecentPriceChange = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setRecentAdjustpriceDate(tRecentPriceChange);
                        }
                        //最近调价价格
                        else if(tFiledName.equals("RecentAdjustpricePrice")){
                            String tRecentPrice = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            product.setRecentAdjustedPrice(Double.parseDouble(tRecentPrice));
           
                        }
                        //产品附加属性
                        else if(tFiledName.equals("AppenderProperties")){
                            String tExProperties = PoiUtil.getCellValue(tHSSFRow, j, "");
                            product.setAppenderProperty(tExProperties);
                        }  
                        //备注
                        else if(tFiledName.equals("Remark")){
                            String tRemark=tHSSFRow.getCell((short)j).getStringCellValue().trim();
                            product.setRemark(tRemark);
                        }                        
                        //是否交易平台的产品
                        else if(tFiledName.equals("IsTradeflatManufacture")){
                            String tInWarehouse = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            /**
                             * add Jackey by 2008-03-20 根据JZGLBS-45 进行调整
                             * 如果集中采购系统中状态为0,1:对应仓储中为1
                             * 如果集中采购系统中状态为2:对应仓储中为0
                             */
                            if (tInWarehouse.equals("0") || tInWarehouse.equals("1"))
                            {
                                tInWarehouse = ConstDefine.STR_VAL_DEAL;
                            }
                            else
                            {
                                tInWarehouse = ConstDefine.STR_VAL_HAND; 
                            }
                            product.setIsTradeflatProduct(tInWarehouse);
           
                        }
                        //是否销售
                        else if(tFiledName.equals("IsBuy")){
                            String tIsBuy = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            product.setIsBuy(tIsBuy);
                        }                        
                        //是否有效
                        else if(tFiledName.equals("Validity")){
                            String tValidity = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            product.setStatus(tValidity);
                        }
                        
                        if (loginContext != null)
                        {
                            product.setCreateUserId(loginContext.getLoginUserId());
                            product.setCreateUser(loginContext.getLoginUserName());
                            DateUtil du = new DateUtil();
                            product.setCreateTime(du.getFullString());
                            product.setLastUpdateTime(du.getFullString());
                            product.setLastUpdateUserId(loginContext.getLoginUserId());
                            product.setLastUpdateUser(loginContext.getLoginUserName());
                        }
                        else
                        {
                            product.setCreateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            product.setCreateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);
                            DateUtil du = new DateUtil();
                            product.setCreateTime(du.getFullString());
                            product.setLastUpdateTime(du.getFullString());
                            product.setLastUpdateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            product.setLastUpdateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);                           
                        }
                    }
                    
                    product.setIsNormal("1");
                    product.setRecordDate(new DateUtil().getFullString());
                    
                    tGSManufactureUploadVO.setProduct(product);
                    tGSManufactureUploadVO.setFailure_reason(tFailReason);
                    tGSManufactureUploadVO.setInsert_result(String.valueOf(tResult));
                    tGSManufactureUploadVO.setRowNumber(i+1);
                    aList.add(tGSManufactureUploadVO);
                    i++;
                }
            }catch(RuntimeException e){
                LogWriter.error("****Manufacture BatchImport RuntimeEx :["+e.getMessage()+"]");
                throw new GWException("导入数据中某一列数据类型不符合规定.");
            }catch(Error e){
                LogWriter.error("****Manufacture BatchImport ErroeEx :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }catch(Exception e){
                LogWriter.error("****Manufacture BatchImport Ex :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }   
           }
       return i+2;
       }
    /*start chengbiao.he*/
    /*读入分类信息内容*/
    
    private static int getManuCatory(ArrayList aList,HSSFSheet aHSSFSheet, ILoginContext loginContext) throws GWException{
        int i = 0;
        //取得第一行的对象
        HSSFRow tFirstRow = aHSSFSheet.getRow(0);
        DecimalFormat a = new DecimalFormat("#");
        while(true){
           HSSFRow tHSSFRow = aHSSFSheet.getRow(1 + i);
            boolean flag = false;
            try{
                
                for(int j=0; j<13; j++){
                   if(tHSSFRow == null){
                        break;
                    }
                    if(tHSSFRow.getCell((short)j) == null){
                        break;
                    }
                   flag=true;
                   break;
                }
                if(!flag){
                    break;
                }else{
                    GWManufactureUploadVO tGSManufactureUploadVO=new GWManufactureUploadVO();
                    int tResult = 1;
                    String tFailReason = "";
                    
                    WarehouseCategory wc = new WarehouseCategory();

                    for(int j=0; j<=13; j++){
                       //获得EXCEL首行记录
                       String tFiledName = tFirstRow.getCell((short)j).getStringCellValue();
                        //产品编号
                        if(tFiledName.equals("ID")){
                            String tID= String.valueOf(tHSSFRow.getCell((short)j).getStringCellValue());
                            wc.setId(tID);
 
                         //仓库编码  
                        }else if(tFiledName.equals("WarehouseCode")){
                            String tWarehouseCode = tHSSFRow.getCell((short)j).getStringCellValue().trim();
                            wc.setWarehouseCode(tWarehouseCode);
                            
                         //分类编码
                        }else if(tFiledName.equals("CategoryCode")){
                            String tCategoryCode = tHSSFRow.getCell((short)j).getStringCellValue().trim();
                            wc.setCategoryCode(tCategoryCode);
                            
                          //分类名称 
                        }else if(tFiledName.equals("CategoryName")){
                            String tCategoryName = String.valueOf(tHSSFRow.getCell((short)j).getStringCellValue());
                            wc.setCategoryName(tCategoryName);
                            
                        //上级分类编码 
                        }else if(tFiledName.equals("ParentCategoryCode")){
                            String tParentCategoryCode = tHSSFRow.getCell((short)j).getStringCellValue().trim();
                            wc.setParentCategoryCode(tParentCategoryCode);
                        
                         //是否有效   
                        }else if(tFiledName.equals("Status")){
                            String tStatus = tHSSFRow.getCell((short)j).getStringCellValue();
                            wc.setStatus(tStatus);
                        
                         //创建用户ID  
                        }else if(tFiledName.equals("CreateUserId")){
                            String tCreateUserId = tHSSFRow.getCell((short)j).getStringCellValue();
                            wc.setCreateUser(tCreateUserId);
                            
                        //创建用户
                        }else if(tFiledName.equals("CreateUser")){
                           if(tHSSFRow.getCell((short)j) != null && !tHSSFRow.getCell((short)j).toString().equals("")){
                                String tCreateUser = String.valueOf(tHSSFRow.getCell((short)j).getNumericCellValue());
                                wc.setCreateUser(tCreateUser);
                            }
                        //单证创建时间  
                        }else if(tFiledName.equals("CreateTime")){
                            String tCreateTime = tHSSFRow.getCell((short)j).getStringCellValue();
                            wc.setCreateTime(tCreateTime);
                        //最后修改人ID   
                        }else if(tFiledName.equals("LastUpdateUserId")){
                            String tLastUpdateUserId = tHSSFRow.getCell((short)j).getStringCellValue();
                            wc.setLastUpdateUserId(tLastUpdateUserId);
                            
                        //最后修改人    
                        }else if(tFiledName.equals("LastUpdateUser")){
                            String tLastUpdateUser = tHSSFRow.getCell((short)j).getStringCellValue().trim();
                            wc.setLastUpdateUser(tLastUpdateUser);
                            
                        //最后修改时间  
                        }else if(tFiledName.equals("LastUpdateTime")){
                            String tLastUpdateTime = tHSSFRow.getCell((short)j).getStringCellValue();
                            wc.setLastUpdateTime(tLastUpdateTime);
                            
                       
   
                            wc.setCreateUserId(loginContext.getLoginUserId());
                            wc.setCreateUser(loginContext.getLoginUserName());
                        DateUtil du = new DateUtil();
                        wc.setCreateTime(du.getFullString());
                        wc.setLastUpdateTime(du.getFullString());
                        wc.setLastUpdateUserId(loginContext.getLoginUserId());
                        wc.setLastUpdateUser(loginContext.getLoginUserName());
                    }
                    
                    tGSManufactureUploadVO.setWarehouseCategory(wc);
                    //tGSManufactureUploadVO.setFailure_reason(tFailReason);
                    tGSManufactureUploadVO.setInsert_result(String.valueOf(tResult));
                    tGSManufactureUploadVO.setRowNumber(i+1);
                    aList.add(tGSManufactureUploadVO);
                    i++;
                }
                }
                }catch(RuntimeException e){
                LogWriter.error("****Manufacture BatchImport RuntimeEx :["+e.getMessage()+"]");
                throw new GWException("导入数据中某一列数据类型不符合规定.");
            }catch(Error e){
                LogWriter.error("****Manufacture BatchImport ErroeEx :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }catch(Exception e){
                LogWriter.error("****Manufacture BatchImport Ex :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }   
           }
       return i+2;
       }
    /*end chengbiao.he*/
    
    /**
     * 写入产品信息导入错误原因
     * @param aErrList
     * @param aSuccList
     * @param aBookIn
     * @param aRowCount
     * @return 
     * @throws GWException
     */
    
    private static String writeManufactureFile(ArrayList aErrList,ArrayList aSuccList,HSSFWorkbook aBookIn,int aRowCount) throws GWException{
        String tOutputPathName = "0";
         try{
            //取得工作薄
             HSSFSheet tHSSFSheet = aBookIn.getSheetAt(0);
             //删除导入成功的记录
             for(int i = 0 ; i < aSuccList.size() ; i++){
                 GWManufactureUploadVO tSuccVO = (GWManufactureUploadVO)aSuccList.get(i);
                 tHSSFSheet.removeRow(tHSSFSheet.getRow(tSuccVO.getRowNumber()));
             }
             //将失败原因写入错误文件
             for(int j = 0 ; j < aErrList.size() ; j++ ){
                 GWManufactureUploadVO tErrVO = (GWManufactureUploadVO)aErrList.get(j);
                 HSSFRow tHSSFRow = tHSSFSheet.getRow(tErrVO.getRowNumber());
                 HSSFCell[] tCell = new HSSFCell[19];
                 tCell[18] = tHSSFRow.getCell((short)18);
                 tCell[18].setEncoding(HSSFCell.ENCODING_UTF_16);
                 tCell[18].setCellValue(tErrVO.getFailure_reason());
                 int k = tErrVO.getRowNumber();
                 if((k-j-1) != 0){
                     tHSSFSheet.shiftRows(k,k,-(k-j-1),true,true);
                     tHSSFSheet.removeRow(tHSSFSheet.getRow(k));
                 }
             }
//
        //  }
             //读取输出文件路径
             String tOutputPath = "C:/errors";
             String tFileName="Manufacture2006";
             //设置输出文件名字
             tOutputPathName = tOutputPath + "/" + tFileName  +".xls";
             java.io.FileOutputStream tOutput = new java.io.FileOutputStream(tOutputPathName);
             //输出错误信息文件
             aBookIn.write(tOutput);
             tOutput.flush();
             tOutput.close();
             
         }catch(Exception e){
             LogWriter.error(e.getMessage());
             return tOutputPathName;
         }
         return tOutputPathName;
    }
    
    /**
     * 批量导入产品种类
     * @param aFile
     * @throws CUPSException
     */
    public static String batchImportManufactureCategory(DataInputStream aFile, DBConnection con, ILoginContext loginContext) throws GWException {

        int tSuccCount = 0;
        int tFailCount = 0;
        String tFailFile = "0";
        HSSFWorkbook tHSSFWorkbook = new HSSFWorkbook();
        HSSFSheet tHSSFSheet = null;
        try{
            //开始读取excel文件
            tHSSFWorkbook = new HSSFWorkbook(aFile);           //读取sheet表单
            //读取sheet表单
            tHSSFSheet = tHSSFWorkbook.getSheetAt(0);
        }catch(Exception e){
            //e.printStackTrace();
            LogWriter.error(e.getMessage());
            throw new GWException("批量上传文件失败");
        }
            ArrayList tList = new ArrayList();
            ArrayList tErrList = new ArrayList();
            ArrayList tSuccList = new ArrayList();
            //读取并检查明细
            int tRowCount =getManufactureCategoryContents(tList,tHSSFSheet, loginContext);
            if(tList.size() > 0){
                for(int i=0; i<tList.size(); i++){
                    GWManufactureCategoryUploadVO tGSManufactureCategoryUploadVO = (GWManufactureCategoryUploadVO)tList.get(i);
                    ProductCategory pc = tGSManufactureCategoryUploadVO.getProductCategory();
                    //GSManufactureCategoryDAO tGSManufactureCategoryDAO=new GSManufactureCategoryDAO();
                    int tResult = Integer.parseInt(tGSManufactureCategoryUploadVO.getInsert_result());
                    if(tResult == 1){
                        tGSManufactureCategoryUploadVO.setProductCategory(pc);
                       try{
                           
                           //判断是否存在种类
                           ProductCategory obj = ProductCategory.fetchByCode(con, pc.getCode());
                           if(obj == null) 
                              obj = ProductCategory.fetch();  
                           obj.setCategoryId1(pc.getCategoryId1());
                           obj.setCategoryId2(pc.getCategoryId2());
                           obj.setCategoryLevel(pc.getCategoryLevel());
                           obj.setCode(pc.getCode());
                           obj.setCreateTime(pc.getCreateTime());
                           obj.setCreateUser(pc.getCreateUser());
                           obj.setCreateUserId(pc.getCreateUserId());
                           obj.setIsTradeflatCategory(pc.getIsTradeflatCategory());
                           obj.setLastUpdateTime(pc.getLastUpdateTime());
                           obj.setLastUpdateUser(pc.getLastUpdateUser());
                           obj.setLastUpdateUserId(pc.getLastUpdateUserId());
                           obj.setName(pc.getName());
                           obj.setRemark(pc.getRemark());
                           obj.setStatus(pc.getStatus());
                           obj.setUpperCategory(pc.getUpperCategory());
                           obj.save(con);                           
                               
                           tSuccCount ++;
                           tGSManufactureCategoryUploadVO.setInsert_result("1");
                           tSuccList.add(tGSManufactureCategoryUploadVO);
                       }catch(Exception e){
                           tFailCount++;
                           tGSManufactureCategoryUploadVO.setInsert_result("0");
                           tGSManufactureCategoryUploadVO.setFailure_reason(e.getMessage());
                           tErrList.add(tGSManufactureCategoryUploadVO);
                       }
                    }else if(tResult == 0){
                        tFailCount++;
                        tErrList.add(tGSManufactureCategoryUploadVO);
                    }
                    
                }
            }
            //将新增失败的商户信息写入文件
            if(tErrList.size() > 0){
                tFailFile = writeManufactureCategoryFile(tErrList,tSuccList,tHSSFWorkbook,tRowCount);
            }
            return tSuccCount+"-"+tFailCount+"-"+tFailFile;
        }
    
    /**
     * 读取excel供应商内容
     * @param aList             ArrayList对象，存放读到的内容
     * @param aSheet            表单
     * @throws CUPSException
     */
    private static int getManufactureCategoryContents(ArrayList aList,HSSFSheet aHSSFSheet, ILoginContext loginContext) throws GWException{
        int i = 0;
        //取得第一行的对象
        HSSFRow tFirstRow = aHSSFSheet.getRow(0);
        
        while(true){
           HSSFRow tHSSFRow = aHSSFSheet.getRow(1 + i);
            boolean flag = false;
            try{
                
                for(int j=0; j<8; j++){
                   if(tHSSFRow == null){
                        break;
                    }
                    if(tHSSFRow.getCell((short)j) == null){
                        break;
                    }
                    if(tHSSFRow.getCell((short)j).getStringCellValue() != null && !tHSSFRow.getCell((short)j).getStringCellValue().equals("")){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    break;
                }else{
                    GWManufactureCategoryUploadVO tGSManufactureCategoryUploadVO = new GWManufactureCategoryUploadVO();
                   
                    int tResult = 1;
                    String tFailReason = "";
                    ProductCategory category = new ProductCategory();
                    
                    
                    for(int j=0; j<8; j++){
                       //获得EXCEL首行记录
                       String tFiledName = tFirstRow.getCell((short)j).getStringCellValue();
                        //产品种类编号
                        if(tFiledName.equals("ManufactureCategoryId")){
                            String tCategoryCode = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setCode(tCategoryCode);
                            
                         //产品种类名称   
                        }else if(tFiledName.equals("ManufactureCategoryName")){
                            String tCategoryName = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setName(tCategoryName);
                            
                         //产品种类描述
                        }else if(tFiledName.equals("ManufactureDesc")){
                            String tCategoryDes = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setRemark(tCategoryDes);
                            
                          //产品种类级别  
                        }else if(tFiledName.equals("ManufactureLevel")){
                            String tCategoryLevel = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setCategoryLevel(tCategoryLevel);
                        //是否交易平台导入 
                        }else if(tFiledName.equals("IsTradeflatManufCategory")){
                            String tIsTradeflatCategory = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            category.setIsTradeflatCategory(tIsTradeflatCategory);                       
                        //产品种类一级编号  
                        }else if(tFiledName.equals("ManufactureCategoryId1")){
                            String tCategoryCode1 = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setCategoryId1(tCategoryCode1);
                        }
                        //产品种类二级编号
                        else if(tFiledName.equals("ManufactureCategoryId2")){
                            String tCategoryCode2 = PoiUtil.getCellValue(tHSSFRow, j, "");
                            category.setCategoryId2(tCategoryCode2);                          
                        }

                        //产品父种类
                        if (category.getCategoryLevel().equals("2"))
                        {
                            category.setUpperCategory(category.getCategoryId1());
                        }
                        else if (category.getCategoryLevel().equals("3"))
                        {
                            category.setUpperCategory(category.getCategoryId2());
                        }
                        
                        //分类状态均为有效
                        category.setStatus(ConstDefine.STR_VALID_YES);
                        
                        if (loginContext != null)
                        {                        
                            DateUtil du = new DateUtil();
                            category.setCreateUserId(loginContext.getLoginUserId());
                            category.setCreateUser(loginContext.getLoginUserName());
                            category.setCreateTime(du.getFullString());
                            category.setLastUpdateUserId(loginContext.getLoginUserId());
                            category.setLastUpdateUser(loginContext.getLoginUserName());
                            category.setLastUpdateTime(du.getFullString());
                        }
                        else
                        {
                            DateUtil du = new DateUtil();
                            category.setCreateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            category.setCreateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);
                            category.setCreateTime(du.getFullString());
                            category.setLastUpdateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            category.setLastUpdateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);
                            category.setLastUpdateTime(du.getFullString());                           
                        }
                    }
                    
                    tGSManufactureCategoryUploadVO.setProductCategory(category);
                    tGSManufactureCategoryUploadVO.setFailure_reason(tFailReason);
                    tGSManufactureCategoryUploadVO.setInsert_result(String.valueOf(tResult));
                    tGSManufactureCategoryUploadVO.setRowNumber(i+1);
                    aList.add(tGSManufactureCategoryUploadVO);
                    i++;
                }
            }catch(RuntimeException e){
                LogWriter.error("****ManufactureCategory BatchImport RuntimeEx :["+e.getMessage()+"]");
                throw new GWException("导入数据中某一列数据类型不符合规定.");
            }catch(Error e){
                LogWriter.error("****ManufactureCategory BatchImport ErroeEx :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }catch(Exception e){
                LogWriter.error("****ManufactureCategory BatchImport Ex :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }   
           }
       return i+2;
       }
    
    /**
     * 写入产品种类导入错误原因
     * @param aErrList
     * @param aSuccList
     * @param aBookIn
     * @param aRowCount
     * @return 
     * @throws GWException
     */
    
    private static String writeManufactureCategoryFile(ArrayList aErrList,ArrayList aSuccList,HSSFWorkbook aBookIn,int aRowCount) throws GWException{
        String tOutputPathName = "0";
         try{
            //取得工作薄
             HSSFSheet tHSSFSheet = aBookIn.getSheetAt(0);
             //删除导入成功的记录
             for(int i = 0 ; i < aSuccList.size() ; i++){
                 GWManufactureCategoryUploadVO tSuccVO = (GWManufactureCategoryUploadVO)aSuccList.get(i);
                 tHSSFSheet.removeRow(tHSSFSheet.getRow(tSuccVO.getRowNumber()));
             }
             //将失败原因写入错误文件
             for(int j = 0 ; j < aErrList.size() ; j++ ){
                 GWManufactureCategoryUploadVO tErrVO = (GWManufactureCategoryUploadVO)aErrList.get(j);
                 HSSFRow tHSSFRow = tHSSFSheet.getRow(tErrVO.getRowNumber());
                 HSSFCell[] tCell = new HSSFCell[7];
                 tCell[5] = tHSSFRow.getCell((short)5);
                 tCell[5].setEncoding(HSSFCell.ENCODING_UTF_16);
                 tCell[5].setCellValue(tErrVO.getFailure_reason());
                 int k = tErrVO.getRowNumber();
                 if((k-j-1) != 0){
                     tHSSFSheet.shiftRows(k,k,-(k-j-1),true,true);
                     tHSSFSheet.removeRow(tHSSFSheet.getRow(k));
                 }
             }
//
        //  }
             //读取输出文件路径
             String tOutputPath = "C:/errors";
             String tFileName="ManufactureCategory2006";
             //设置输出文件名字
             tOutputPathName = tOutputPath + "/" + tFileName  +".xls";
             java.io.FileOutputStream tOutput = new java.io.FileOutputStream(tOutputPathName);
             //输出错误信息文件
             aBookIn.write(tOutput);
             tOutput.flush();
             tOutput.close();
             
         }catch(Exception e){
             LogWriter.error(e.getMessage());
             return tOutputPathName;
         }
         return tOutputPathName;
    }
    
    /**
     * 批量导入供应商信息
     * @param aFile
     * @throws CUPSException
     */
    public static String batchImportProvider(DataInputStream aFile,DBConnection con, ILoginContext loginContext) throws GWException {

        int tSuccCount = 0;
        int tFailCount = 0;
        String tFailFile = "0";
        HSSFWorkbook tHSSFWorkbook = new HSSFWorkbook();
        HSSFSheet tHSSFSheet = null;
        try{
            //开始读取excel文件
            tHSSFWorkbook = new HSSFWorkbook(aFile);           //读取sheet表单
            //读取sheet表单
            tHSSFSheet = tHSSFWorkbook.getSheetAt(0);
        }catch(Exception e){
            //e.printStackTrace();
            LogWriter.error(e.getMessage());
            throw new GWException("批量上传文件失败");
        }
            ArrayList tList = new ArrayList();
            ArrayList tErrList = new ArrayList();
            ArrayList tSuccList = new ArrayList();
            //读取并检查明细
            int tRowCount =getProviderContents(tList,tHSSFSheet, loginContext);
            
            if(tList.size() > 0){
                for(int i=0; i<tList.size(); i++){
                    GWProviderUploadVO tGSProviderUploadVO = (GWProviderUploadVO)tList.get(i);
                    Provider pro = tGSProviderUploadVO.getProvider();
                    
                    int tResult = Integer.parseInt(tGSProviderUploadVO.getInsert_result());
                    if(tResult == 1){
                        tGSProviderUploadVO.setProvider(pro);
                       try{
                           //判断供应商是否存在
                           Provider obj = Provider.fetchByCode(con, pro.getCode());
                           if(obj == null) 
                              obj = Provider.fetch();
                           obj.setAddress(pro.getAddress());
                           obj.setCode(pro.getCode());
                           obj.setComProperty(pro.getComProperty());
                           obj.setCountryCode(pro.getCountryCode());
                           obj.setCreateTime(pro.getCreateTime());
                           obj.setCreateUser(pro.getCreateUser());
                           obj.setCreateUserId(pro.getCreateUserId());
                           obj.setCreditLevel(pro.getCreditLevel());
                           obj.setDistrictCode(pro.getDistrictCode());
                           obj.setEngName(pro.getEngName());
                           obj.setFullName(pro.getFullName());
                           obj.setIndustry(pro.getIndustry());
                           obj.setIsTradeflatProvider(pro.getIsTradeflatProvider());
                           obj.setLastUpdateTime(pro.getLastUpdateTime());
                           obj.setLastUpdateUser(pro.getLastUpdateUser());
                           obj.setLastUpdateUserId(pro.getLastUpdateUserId());
                           obj.setLinkPerson(pro.getLinkPerson());
                           obj.setLinkTel(pro.getLinkTel());
                           obj.setMainRpoduct(pro.getMainRpoduct());
                           obj.setManagePerson(pro.getManagePerson());
                           obj.setManagerTel(pro.getManagerTel());
                           obj.setName(pro.getName());
                           obj.setProvinceCode(pro.getProvinceCode());
                           obj.setScope(pro.getScope());
                           obj.setStatus(pro.getStatus());
                           obj.setZipCode(pro.getZipCode());
                           obj.save(con);                           
                           
                           tSuccCount ++;
                           tGSProviderUploadVO.setInsert_result("1");
                           tSuccList.add(tGSProviderUploadVO);
                       }catch(Exception e){
                           tFailCount++;
                           tGSProviderUploadVO.setInsert_result("0");
                           tGSProviderUploadVO.setFailure_reason(e.getMessage());
                           tErrList.add(tGSProviderUploadVO);
                       }
                    }else if(tResult == 0){
                        tFailCount++;
                        tErrList.add(tGSProviderUploadVO);
                    }
                    
                }
            }
            //将新增失败的供应商信息写入文件
            if(tErrList.size() > 0){
                tFailFile = writeProviderFile(tErrList,tSuccList,tHSSFWorkbook,tRowCount);
            }
            return tSuccCount+"-"+tFailCount+"-"+tFailFile;
        }
    /*批量导入分类信息*/
/*start chengbiao.he*/
  /*  public static String batchImportCatory(DBConnection con,DataInputStream dfile)throws Exception{
        HSSFWorkbook hssfWorkBook = new HSSFWorkBook();
        HSSFSheet hssfSheet = null;
        try{
            hssfSheet = new HSSFWorkBook(dfile);
            hssfSheet = hssfWorkBook.getSheetAt(0);
        }catch(IOException e){
            e.getStackTrace();
        }
        ArrayList alist = new ArrayList();
        
        
        return ;
        
    }
    */
    /*end chengbiao.he*/
    
    /**
     * 读取excel供应商文档内容
     * @param aList             ArrayList对象，存放读到的内容
     * @param aSheet            表单
     * @throws CUPSException
     */
    private static int getProviderContents(ArrayList aList,HSSFSheet aHSSFSheet, ILoginContext loginContext) throws GWException{
        int i = 0;
        //取得第一行的对象
        HSSFRow tFirstRow = aHSSFSheet.getRow(0);
        
        while(true){
           HSSFRow tHSSFRow = aHSSFSheet.getRow(1 + i);
            boolean flag = false;
            try{
                
                for(int j=0; j<19; j++){
                   if(tHSSFRow == null){
                        break;
                    }
                    if(tHSSFRow.getCell((short)j) == null){
                        break;
                    }
                    flag = true;
                    break;
                }
                if(!flag){
                    break;
                }else{
                    GWProviderUploadVO tGSProviderUploadVO = new GWProviderUploadVO();
                    Provider provider = Provider.fetch();
                   
                    int tResult = 1;
                    String tFailReason = "";
                            
                    
                    for(int j=0; j<19; j++){
                       //获得EXCEL首行记录
                       String tFiledName = tFirstRow.getCell((short)j).getStringCellValue();
                        //供应商编号
                        if(tFiledName.equals("ProviderId")){
                            String tProviderId = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setCode(tProviderId);    
                           
                         //供应商简称   
                        }else if(tFiledName.equals("ProviderShortname")){
                            String tProviderShortName = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setName(tProviderShortName);
                            
                         //供应商全称
                        }else if(tFiledName.equals("ProviderName")){
                            String tProviderName = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setFullName(tProviderName);
                            
                          //供应商英文名称
                        }else if(tFiledName.equals("ProviderEngname")){
                            String tProviderEngname = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setEngName(tProviderEngname);
                            
                        //公司性质  
                        }else if(tFiledName.equals("CorpProperty")){
                            String tCorpProperty = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setComProperty(tCorpProperty);
                        }
                        //经营地址
                        else if(tFiledName.equals("CorpAddr")){
                           String tCorpAddr = PoiUtil.getCellValue(tHSSFRow, j, "");
                           provider.setAddress(tCorpAddr);
                        }
                        //邮政编码
                        else if(tFiledName.equals("CorpPost")){
                            String tCorpPost = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setZipCode(tCorpPost);
                         }
                        //负责人
                        else if(tFiledName.equals("PrincipalId")){
                            String tPrincipalId = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setManagePerson(tPrincipalId);
                         }
                        //负责人联系电话
                        else if(tFiledName.equals("PrincipalPhone")){
                            String tPrincipalPhone = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setManagerTel(tPrincipalPhone);
                         }
                        //联系人
                        else if(tFiledName.equals("ContactId")){
                            String tContactId = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setLinkPerson(tContactId);
                         }
                        //联系人电话
                        else if(tFiledName.equals("ContactPhone")){
                            String tContactPhone = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setLinkTel(tContactPhone);
                         }
                        //所属国家
                        else if(tFiledName.equals("ResideCountry")){
                            String tResideCountry = PoiUtil.getCellValue(tHSSFRow, j, "China");
                            provider.setCountryCode(tResideCountry);
                         }
                        //所属省份
                        else if(tFiledName.equals("ResideProvince")){
                            String tResideProvince = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setProvinceCode(tResideProvince);
                        }
                        //所属城市
                        else if(tFiledName.equals("ResideCity")){
                            String tResideCity = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setDistrictCode(tResideCity);
                         }
                        //主营行业
                        else if(tFiledName.equals("WorkTrade")){
                            String tWorkTrade = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setIndustry(tWorkTrade);
                         }
                        //主营产品
                        else if(tFiledName.equals("WorkManufacture")){
                            String tWorkManufacture = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setMainRpoduct(tWorkManufacture);
                         }
                        //经营范围
                        else if(tFiledName.equals("WorkScope")){
                            String tWorkScope = PoiUtil.getCellValue(tHSSFRow, j, "");
                            provider.setScope(tWorkScope);
                         }
                        //是否交易平台会员
                        else if(tFiledName.equals("IsTradeflatProvider")){                            
                            String tIsTradeflatProvider = PoiUtil.getCellValue(tHSSFRow, j, "1");
                            if (tIsTradeflatProvider.equalsIgnoreCase("0"))
                            {
                                tIsTradeflatProvider = ConstDefine.STR_VAL_DEAL;
                            }
                            else
                            {
                                tIsTradeflatProvider = ConstDefine.STR_VAL_HAND;
                            }
                            provider.setIsTradeflatProvider(tIsTradeflatProvider);                            
                        }        
                        //有效性
                        else if(tFiledName.equals("Validity")){
                            String tValidity = PoiUtil.getCellValue(tHSSFRow, j, "0");
                            provider.setStatus(tValidity);
                         }
                        if (loginContext != null)
                        {
                            provider.setCreateUserId(loginContext.getLoginUserId());
                            provider.setCreateUser(loginContext.getLoginUserName());
                            DateUtil du = new DateUtil();
                            provider.setCreateTime(du.getFullString());
                            provider.setLastUpdateUserId(loginContext.getLoginUserId());
                            provider.setLastUpdateUser(loginContext.getLoginUserName());
                            provider.setLastUpdateTime(du.getFullString());
                        }
                        else
                        {
                            provider.setCreateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            provider.setCreateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);
                            DateUtil du = new DateUtil();
                            provider.setCreateTime(du.getFullString());
                            provider.setLastUpdateUserId(ConstDefine.EXCELFILE_CREATE_USER_ID_AUTO);
                            provider.setLastUpdateUser(ConstDefine.EXCELFILE_CREATE_USER_AUTO);
                            provider.setLastUpdateTime(du.getFullString());                           
                        }
                    }
                    
                    tGSProviderUploadVO.setProvider(provider);
                    tGSProviderUploadVO.setFailure_reason(tFailReason);
                    tGSProviderUploadVO.setInsert_result(String.valueOf(tResult));
                    tGSProviderUploadVO.setRowNumber(i+1);
                    aList.add(tGSProviderUploadVO);
                    i++;
                }
            }catch(RuntimeException e){
                LogWriter.error("****Provider BatchImport RuntimeEx :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }catch(Error e){
                LogWriter.error("****Provider BatchImport ErroeEx :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }catch(Exception e){
                LogWriter.error("****Provider BatchImport Ex :["+e.getMessage()+"]");
                throw new GWException(e.getMessage());
            }   
           }
       return i+2;
       }
    /**/
    
    /**
     * 写入供应商信息导入错误原因
     * @param aErrList
     * @param aSuccList
     * @param aBookIn
     * @param aRowCount
     * @return 
     * @throws GWException
     */
    
    private static String writeProviderFile(ArrayList aErrList,ArrayList aSuccList,HSSFWorkbook aBookIn,int aRowCount) throws GWException{
        String tOutputPathName = "0";
         try{
            //取得工作薄
             HSSFSheet tHSSFSheet = aBookIn.getSheetAt(0);
             //删除导入成功的记录
             for(int i = 0 ; i < aSuccList.size() ; i++){
                 GWProviderUploadVO tSuccVO = (GWProviderUploadVO)aSuccList.get(i);
                 tHSSFSheet.removeRow(tHSSFSheet.getRow(tSuccVO.getRowNumber()));
             }
             //将失败原因写入错误文件
             for(int j = 0 ; j < aErrList.size() ; j++ ){
                 GWProviderUploadVO tErrVO = (GWProviderUploadVO)aErrList.get(j);
                 HSSFRow tHSSFRow = tHSSFSheet.getRow(tErrVO.getRowNumber());
                 HSSFCell[] tCell = new HSSFCell[18];
                 tCell[17] = tHSSFRow.getCell((short)17);
                 tCell[17].setEncoding(HSSFCell.ENCODING_UTF_16);
                 tCell[17].setCellValue(tErrVO.getFailure_reason());
                 int k = tErrVO.getRowNumber();
                 if((k-j-1) != 0){
                     tHSSFSheet.shiftRows(k,k,-(k-j-1),true,true);
                     tHSSFSheet.removeRow(tHSSFSheet.getRow(k));
                 }
             }

             //读取输出文件路径
             String tOutputPath = "C:/errors";
             String tFileName="Provider2006";
             //设置输出文件名字
             tOutputPathName = tOutputPath + "/" + tFileName  +".xls";
             java.io.FileOutputStream tOutput = new java.io.FileOutputStream(tOutputPathName);
             //输出错误信息文件
             aBookIn.write(tOutput);
             tOutput.flush();
             tOutput.close();
             
         }catch(Exception e){
             LogWriter.error(e.getMessage());
             return tOutputPathName;
         }
         return tOutputPathName;
    }

    
	/**
	 * 读取筛选产品excel产品信息文档内容
	 * @param aList             ArrayList对象，存放读到的内容
	 * @param aSheet            表单
	 * @throws CUPSException
	 */
	/*private static int getManufactureFilterContents(ArrayList aList,HSSFSheet aHSSFSheet) throws GSException
	{
		int i = 0;
		int k = 0;
		//取得第一行的对象
		HSSFRow tFirstRow = aHSSFSheet.getRow(0);
		while(true)
		{
			boolean flag = false;
			
		    HSSFRow tHSSFRow = aHSSFSheet.getRow(1 + k);
		    
		    k++;			
			try
			{
				for(int j=0; j<2; j++){
				   if(tHSSFRow == null){
						break;
					}
					if(tHSSFRow.getCell((short)j) == null){
						break;
					}
				    flag=true;
				    break;
				}
				
				if(!flag)
				{
					break;
				}
				else
				{				
					
					GSManufactureFilterUploadVO tGSManufactureFilterUploadVO = new GSManufactureFilterUploadVO();
					int tResult = 1;
					String tFailReason = "";
					GSManufactureFilterUploadBean tGSManufactureFilterUploadBean = new GSManufactureFilterUploadBean();
					
					HSSFCell tCell = null;
					String tDCode= "";
					String tConcentricityCode = "";
					String tManufactureCode = "";
					String tIsGSUse = "0";
					String tColStr = "";
					
					for(int m=0;m<tFirstRow.getLastCellNum();m++)
					{						
						tColStr = PoiUtil.getCellValue(tFirstRow,m,"");
						
						if (tColStr.equalsIgnoreCase("*分站代码"))
						{
							//分站编码
							tDCode = PoiUtil.getCellValue(tHSSFRow,m,"");
						}
						else if(tColStr.equalsIgnoreCase("*产品18位编码"))	
						{
							//18位产品编码
							tManufactureCode = PoiUtil.getCellValue(tHSSFRow,m,"");						
						}
						else if(tColStr.equalsIgnoreCase("产品自编码"))
						{
							//集中编码
							tConcentricityCode = PoiUtil.getCellValue(tHSSFRow,m,"");  							
						}
						else if(tColStr.equalsIgnoreCase("*巴士物资使用"))
						{
							//是否集中采购使用                	
							tIsGSUse = PoiUtil.getCellValue(tHSSFRow,m,""); 
							if (!tIsGSUse.equalsIgnoreCase("1")) tIsGSUse = "0";							
						}
					}										                       	
                    
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					String buf = df.format(new java.util.Date(System.currentTimeMillis()));                    
                    
					tGSManufactureFilterUploadBean.setGs_manufacture_id(tManufactureCode);
					tGSManufactureFilterUploadBean.setGs_concentricity_id(tConcentricityCode);
					tGSManufactureFilterUploadBean.setGs_inport_time(buf);
                     
               	 	//由于筛选产品功能是上海巴士物资提出的，在此未做该功能只针对上海巴士物资的限制，是针对以后非上海站有类似需求   
					if (GSSystemConfigurator.getProjectVersion().equalsIgnoreCase(tDCode) 
						&& tIsGSUse.equalsIgnoreCase("1") 
						&& !tManufactureCode.equalsIgnoreCase(""))
					{   
                    	tGSManufactureFilterUploadVO.setGSManufactureFilterUploadBean(tGSManufactureFilterUploadBean);
						tGSManufactureFilterUploadVO.setFailure_reason(tFailReason);
						tGSManufactureFilterUploadVO.setInsert_result(String.valueOf(tResult));
						tGSManufactureFilterUploadVO.setRowNumber(k);
						aList.add(tGSManufactureFilterUploadVO);
						i++;
					}
					else
					{
						String tReson = "";
						if (!GSSystemConfigurator.getProjectVersion().equalsIgnoreCase(tDCode))
						{
							tReson = "产品不属于该分站"; 
						}
						else if (!tIsGSUse.equalsIgnoreCase("1") )
						{
							tReson = "产品不为集中采购使用";
						}
						else if(tManufactureCode.equals(""))
						{
							tReson = "产品18位编码错误！";
						}					
						else
						{
							tReson = "产品数据格式错误！";
						}
						
						tGSManufactureFilterUploadVO.setGSManufactureFilterUploadBean(tGSManufactureFilterUploadBean);
						tGSManufactureFilterUploadVO.setFailure_reason(tReson);
						tGSManufactureFilterUploadVO.setInsert_result("0");
						tGSManufactureFilterUploadVO.setRowNumber(k);
						aList.add(tGSManufactureFilterUploadVO);
						i++;
					}
				}

			}catch(RuntimeException e){
				GSLogWriter.error("****GSFileUploadProcessor batchImportFilterManufacture RuntimeEx :["+e.getMessage()+"]");
				throw new GSException("导入数据中某一列数据类型不符合规定.");
			}catch(Error e){
				GSLogWriter.error("****GSFileUploadProcessor batchImportFilterManufacture ErroeEx :["+e.getMessage()+"]");
				throw new GSException(e.getMessage());
			}catch(Exception e){
				GSLogWriter.error("****GSFileUploadProcessor batchImportFilterManufacture Ex :["+e.getMessage()+"]");
				throw new GSException(e.getMessage());
			} 	   		
		}		
		return i;
	}*/
	
	/**
	 * 记录不符合的筛选产品信息
	 * @param aErrList
	 * @param aSuccList
	 * @param aBookIn
	 * @param aRowCount
	 * @return 
	 * @throws GSException
	 */
    
	/*private static String writeManufactureFilterUploadFile(ArrayList aErrList,ArrayList aSuccList,HSSFWorkbook aBookIn,int aRowCount) throws GSException
	{
		String tOutputPathName = "0";
		//读取输出文件路径
		String tOutputPath = GSSystemConfigurator.getParam("gs.down.savepath");
		String tFileName = "Failure_ManufactureFilterUpload_";
		try
		{
			//取得工作薄
			HSSFSheet tHSSFSheet = aBookIn.getSheetAt(0);
			//删除导入成功的记录
			for(int i = 0 ; i < aSuccList.size() ; i++)
			{
				GSManufactureFilterUploadVO tSuccVO = (GSManufactureFilterUploadVO)aSuccList.get(i);
				tHSSFSheet.removeRow(tHSSFSheet.getRow(tSuccVO.getRowNumber()));
			}
			//将失败原因写入错误文件
			for(int j = 0 ; j < aErrList.size() ; j++ )
			{
				GSManufactureFilterUploadVO tErrVO = (GSManufactureFilterUploadVO)aErrList.get(j);
				HSSFRow tHSSFRow = tHSSFSheet.getRow(tErrVO.getRowNumber());
				HSSFCell tCell = null;				
				tCell = tHSSFRow.createCell(tHSSFRow.getLastCellNum());
				tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				tCell.setCellValue(tErrVO.getFailure_reason());
				int k = tErrVO.getRowNumber();
				if((k-j-1) != 0)
				{
					tHSSFSheet.shiftRows(k,k,-(k-j-1),true,true);
					tHSSFSheet.removeRow(tHSSFSheet.getRow(k));
				}
			}

			SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
			String buf = df.format(new java.util.Date(System.currentTimeMillis())); 
			
			tFileName += buf + ".xls";
			
			//设置输出文件名字
			tOutputPathName = tOutputPath + "/" + tFileName ;
			java.io.FileOutputStream tOutput = new java.io.FileOutputStream(tOutputPathName);
			//输出错误信息文件
			aBookIn.write(tOutput);
			tOutput.flush();
			tOutput.close();
             
		 }catch(Exception e){
			 GSLogWriter.error("记录不符合的筛选产品信息错误："+e.getMessage());
			 return "0";
		 }
		 return tFileName;
	}*/	
	
}

